package com.py.credit.service.impl;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import com.py.credit.dao.PromiseBookApprovalDao;
import com.py.credit.entity.PromiseBookReport;
import com.py.credit.service.PromiseBookApprovalService;
import com.py.credit.utils.SQLBuilder;
import com.py.framework.core.common.Page;
import com.py.framework.core.exception.ServiceException;

@Service
public class PromiseBookApprovalServiceImpl implements PromiseBookApprovalService{
	
	@Autowired
	PromiseBookApprovalDao promiseBookApprovalDao;

	@Override
	public List<Map<String,Object>> getPromiseBooksByConditionForPage(String type,String ztType,String lyzt,String relationStatus ,
			Long deptId , List<String> showColumns, String[] additionalColumns, String condition, Page page,String sbtype,Long userId ) {
		String tablename = "";
		if("1".equals(type)) {
			tablename = "t_1000000010402_qAcqVkiVSN";
		}else if("2".equals(type)) {
			tablename = "t_1000000010400_h65MpMNqWZ";
		}else if("3".equals(type)) {
			tablename = "t_1000000010399_aUDgU4MoxP";
		}else if("4".equals(type)) {
			tablename = "t_1000000010398_7BQJb5pmyp";
		}
		if (CollectionUtils.isEmpty(showColumns)) {
            throw new ServiceException("至少选择一列");
        }
        List<String> conditions = SQLBuilder.createConditionSql(condition);
        
        List<Map<String, Object>> list = promiseBookApprovalDao.getPromiseBooksByConditionForPage(type,ztType,lyzt,relationStatus,deptId,showColumns,additionalColumns, conditions, page,sbtype,userId,tablename);
		
		return list;
	}
	
	public List<String> selectTybm(String tableName,String fieldZtName,String ztName,String fieldTyshbm,String tyshxydm){
		return promiseBookApprovalDao.selectTybm(tableName, fieldZtName, ztName, fieldTyshbm, tyshxydm);
	}
	

	@Override
	public int approvalPromiseBook(Long userId , String userName ,Long id , String bookStatus , String approvalOpinion , String tybm,String relationStatus) {
        return promiseBookApprovalDao.approvalPromiseBook(userId , userName ,id,bookStatus,approvalOpinion , tybm , relationStatus);
		
	}

	@Override
	public List<String> selectTybmByZt(String ztName,String tyshxydm ,String tableName , String field1 , String field2) {
		return promiseBookApprovalDao.selectTybmByZt(ztName,tyshxydm , tableName,field1,field2);
	}
	
	@Override
	public void renewPromiseBooks(String tybm,Long id) {
		promiseBookApprovalDao.renewPromiseBooks(tybm , id);
	}
	
	@Override
	public String promiseBookPreview(Long id) {
		return promiseBookApprovalDao.promiseBookPreview(id);
	}

	@Override
	public List<Map<String, Object>> getWspDatas() {
		return promiseBookApprovalDao.getWspDatas();
	}

	@Override
	public Map<String, String> selectOne(Long id) {
		return promiseBookApprovalDao.selectOne(id);
	}
	
	public List<Map<String, Object>> selectXycnForPage( String name,String startTime,String endTime, String type, Page page){
		return promiseBookApprovalDao.selectXycnForPage(name, startTime,endTime, type, page);
	}

}
